import {GModalForm} from 'geminis-react';
import * as CryptoJS from 'crypto-js';
import {useCallback} from "react";

export const UserPassword = (props: { id: string, username: string }) => {

    const onSubmitting = useCallback((value: any) => {
        value.id = props.id;
        value.username = props.username;
        value.password = CryptoJS.SHA256(value.passwordConfirm).toString();
        delete value.passwordConfirm;
    }, [])

    const schema = {
        schemaPath: '/auth-pc/schema/user/password.json',
        schema: {
            data: {
                autoload: false,
                url: '/api/auth/password',
            }
        },
        onSubmitting: onSubmitting
    }

    return (
        <GModalForm
            button={{
                text: '设置密码',
                button: {
                    type: "link"
                }
            }}
            form={schema}
        />
    );
};
